package com.yanqu.road.logic.activity.hotpotjump.game;

import java.util.ArrayList;
import java.util.List;

public enum eJumpDirection {
    /**
     * 不在直线
     */
    None(0, "", null),
    /**
     * 右上
     */
    RightUp(1, "↗", new int[]{1, -1}),
    /**
     * 右
     */
    Right(2, "→", new int[]{1, 0}),
    /**
     * 右下
     */
    RightDown(3, "↘", new int[]{0, 1}),
    /**
     * 左下
     */
    LeftDown(4, "↙", new int[]{-1, 1}),
    /**
     * 左
     */
    Left(5, "←", new int[]{-1, 0}),
    /**
     * 左上
     */
    LeftUp(6, "↖", new int[]{0, -1}),


    ;

    private int value;
    private String printfStr;
    private int[] qrDiff;

    private eJumpDirection(int value, String printfStr, int[] qrDiff) {
        this.value = value;
        this.printfStr = printfStr;
        this.qrDiff = qrDiff;
    }

    public int getValue() {
        return value;
    }

    public String getPrintfStr() {
        return printfStr;
    }

    public int[] getQrDiff() {
        return qrDiff;
    }

    /**
     * 获得反方向
     */
    public eJumpDirection getOppositeDirection() {
        if (this == Left) {
            return Right;
        } else if (this == Right) {
            return Left;
        } else if (this == LeftUp) {
            return RightDown;
        } else if (this == RightDown) {
            return LeftUp;
        } else if (this == LeftDown) {
            return RightUp;
        } else if (this == RightUp) {
            return LeftDown;
        } else {
            return None;
        }
    }

    /**
     * 获得顺时针走一圈的方向列表
     */
    public List<eJumpDirection> getClockwiseDirections() {
        List<eJumpDirection> allValidDirections = getAllValidDirections();
        int startIndex = allValidDirections.indexOf(this);
        startIndex += 2;
        List<eJumpDirection> result = new ArrayList<>();
        for (int i = startIndex; i < startIndex + 6; i++) {
            result.add(allValidDirections.get(i % 6));
        }
        return result;
    }


    public static eJumpDirection getDirection(int value) {
        for (eJumpDirection direction : eJumpDirection.values()) {
            if (direction.value == value) {
                return direction;
            }
        }
        return None;
    }

    /**
     * 有效的方位
     * @return
     */
    public static List<eJumpDirection> getAllValidDirections(){
        List<eJumpDirection> directions = new ArrayList<>();
        for (eJumpDirection direction : eJumpDirection.values()) {
            if (direction != None) {
                directions.add(direction);
            }
        }
        return directions;
    }
}
